<?php
	require_once "user.php";
	require_once "member.php";

class auth{

	public function __construct(){
		session_start();
	}
	
	//mengecek email dan password dari inputan pada login
	public function login_member($email,$password){	
			$User_Dao=new User_Dao();
			
			if ($email=="" && $password==""){
			//echo '1';
				$w1="Silahkan isikan email dan password terlebih dahulu!";
				$togo="login.php";
				header ("Location: $togo");
			}

			if($User_Dao->cek_user($email,$password)==false){
			//echo '2';
				$togo="login.php";
				header ("Location: $togo");
			}

			if($User_Dao->cek_user($email,$password)==true){
				$nama=$User_Dao->get_email($email);   //menyimpan array user berdasarkan parameter email
				if($nama->role=="admin"){
					//echo '1';
					$_SESSION['MM_Username'] = "admin";
					$togo="admin/beranda_admin.php";
					header ("Location:$togo");
				}
				
				if($nama->role=="member"){
					//echo '2';
					$Member_Dao=new Member_Dao();
					$member=$Member_Dao->get_id($nama->id);
					$_SESSION['MM_Username'] = $member->nama;
					$_SESSION['MM_Id'] = $member->id;
					$_SESSION['MM_Email'] = $email;
					$togo="member/beranda_member.php";
					header ("Location:$togo");
				}
				
			}
	}
	
	//untuk keluar dari session
	public function logout(){
		session_destroy();
		$togo="login.php";
		header ("Location:$togo");
	
	}
	

}